#！/bin/bash

# 项目快速启动
# [1] 加载项目运行的虚拟环境
cd /home/Leonis/program/dsp/website/
source ./venv/bin/activate

# [2]关闭当前 Web 服务
ps -ef|grep "8090" |cut -c 9-15|xargs kill -9
sleep 5

# [3]关闭当前正在运行 Celery Worker 以及 Celery Beat
ps -ef|grep "celery"|cut -c 9-15|xargs kill -9
sleep 5

# [4]删除无效日志文件
rm -rf ./*.log
rm -f nohup.out

# [5]删除 Celery 文件
rm -rf ./*.pid
rm -f ./celery*

# [6]删除缓存文件
rm -rf ./website/__pycache__/
rm -rf ./ddm/__pycache__/
rm -rf ./ddm/migrations/__pycache__/
rm -rf ./login/__pycache__/
rm -rf ./login/migrations/__pycache__/

# [7]后台启动多个 Celery Worker
celery multi restart worker01 -A website --loglevel=error
celery multi restart worker02 -A website --loglevel=error
celery multi restart worker03 -A website --loglevel=error
celery multi restart worker04 -A website --loglevel=error

# [8]后台启动 Celery Beat
celery -A website beat --loglevel=error --detach
sleep 2

# [9] 启动 Web 服务
nohup python manage.py runserver --insecure 0.0.0.0:8090 > nohup.log 2>&1 &

# [10] 退出虚拟环境
deactivate

